package firstquestion;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class StudentMessageManage {
    private static List<Student> studentList=new ArrayList<Student>();
    static {
        studentList.add(new Student(1,"威廉蒋",24,"340721199512183314"));
        studentList.add(new Student(2,"菲里芝",36,"340721199512183314"));
        studentList.add(new Student(3,"克里斯",18,"340721199512183314"));
    }

    public static void showStudent(){
        Iterator<Student> it=studentList.listIterator();
        System.out.println("学号\t姓名\t\t年龄\t身份证");
        while (it.hasNext()){
            Student student=it.next();
            System.out.println(student.getSno()+"\t"+student.getName()+"\t"+student.getAge()+
                    "\t"+student.getIdcard());
        }
    }

    public static boolean delete(String name){
        boolean falg=false;
        for (int i = 0; i <studentList.size() ; i++) {
            if (studentList.get(i).getName().equals(name)){
                studentList.remove(i);
                falg=true;
            }
        }
        if (!falg){
            return true;
        }else {
            return false;
        }
    }
    public static void add(Student student) {
        boolean falg = false;
        for (int i = 0; i < studentList.size(); i++) {
            if (studentList.get(i).getSno() == student.getSno()) {

                falg = true;
            }
        }
        if (falg) {
            System.out.println("学号重复了，请重新添加:");
        } else {
            studentList.add(student);
            System.out.println("添加成功!");
        }
    }

    public static void update(Student student) {
        boolean falg = false;
        for (int i = 0; i < studentList.size(); i++) {
            if (studentList.get(i).getSno() == student.getSno()) {
                Student stu = studentList.get(i);
                int index = studentList.indexOf(stu);
                studentList.set(index, student);
                falg = true;

            }
        }
        if (falg) {
            System.out.println("修改成功");
        }else {
            System.out.println("你需要修改的学生不存在");
        }
    }

    public static void exit(){
        System.out.println("谢谢使用");
    }
}
